<template>
  <div class="dashboard-container">
    <h2 class="head-big-title">Log Aktiviti</h2>
    <el-form label-position="top" label-width="80px" :model="searchData" style="width: 92%;margin: 20px 4% 0 4%;padding: 10px 2% 3px 2%;border-radius: 10px;background-color: white;text-align: left;clear: both;">
      <el-form-item label="Nama" class="one-form-item">
        <el-input v-model="searchData.operUserName" @blur="loadData" placeholder="Nama"></el-input>
      </el-form-item>
      <el-form-item label="Tarikh" class="one-form-item">
        <el-date-picker
          @input="changeNew($event)"
          @change="loadData"
          v-model="searchData.startTime"
          type="datetime"
          placeholder="Tarikh">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="Kategori" class="one-form-item">
        <el-select v-model="searchData.operType" @change="loadData" placeholder="Kategori">
          <el-option label="Semua" value=""></el-option>
          <el-option label="Log Masuk" value="login"></el-option>
          <el-option label="Cipta" value="Create"></el-option>
          <el-option label="Tambah" value="Add"></el-option>
          <el-option label="Edit" value="Edit"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div style="width: 96%;margin: 20px 2% 0 2%;padding-left: 10px;border-radius: 20px;background-color: rgb(245,246,247);text-align: left;">
      <div v-for="(item,index) in tableData" :key="index" style="width: 100%;padding: 16px 20px 15px 15px;border-radius: 10px;background-color: white;margin-bottom: 10px;">
        <div style="width: 100%;">
          <strong style="width: 35%;display: inline-block;">Tarikh</strong>
          <p style="display: inline-block;">{{$getTime(item.operCreateTime)}}</p>
        </div>
        <div style="width: 100%;">
          <strong style="width: 35%;display: inline-block;">Nama</strong>
          <p style="display: inline-block;">{{(item.operUserId)}}</p>
        </div>
        <div style="width: 100%;">
          <strong style="width: 35%;display: inline-block;">Kategori</strong>
          <p style="display: inline-block;">{{(item.operType)}}</p>
        </div>
        <div style="width: 100%;">
          <strong style="width: 35%;display: inline-block;">Aktiviti</strong>
          <p style="display: inline-block;">{{(item.operDesc)}}</p>
        </div>
        <div style="width: 100%;">
          <strong style="width: 35%;display: inline-block;">Penerangan</strong>
          <p style="display: inline-block;">{{(item.operMethod)}}</p>
        </div>
      </div>
    </div>
    <el-pagination
      style="clear: top;float: right;margin: 16px 3% 15px 0;"
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :current-page="searchData.pageIndex"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { operation_log_queryApi } from '@/api/user'

export default {
  name: 'Activityrecord',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data() {
    return {
      tableData: [],
      searchData: {
        pageNum: 10,
        pageIndex: 1
      },
      loading: false,
      orderChart: '',
      total: 0
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    changeNew() {
      this.$forceUpdate()
    },
    toPage() {
      this.$router.push({
        path: '/Products/Product_Add'
      })
    },
    handleCurrentChange(val) {
      this.searchData.pageIndex = val
      this.loadData()
    },
    loadData() {
      operation_log_queryApi(this.searchData).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
      }).catch(err => {
        console.log(err)
      })
    }, // 得到数据表格
    handleEdit(row) {
      this.$router.push({
        path: `/Products/product_Detail/${row.id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .head-big-title{
    text-align: left;
    font-size: 20px;
    margin: 20px 0 0 3%;
  }
  .dashboard-container{
    margin-top: 20px;
    text-align: center;
  }
  .one-form-item{
    display: block;
    .el-select{
      width: 100%;
    }
    .el-input{
      width: 100%;
    }
  }
</style>
<style scoped>
  /deep/.head-search label{
    line-height: 30px;
  }
</style>
